/**
 * 送礼界面
 */
class GiftUI extends UIBase{
    private group_1:eui.Group;
    private group_2:eui.Group;
    private img_tittle:eui.Image;
    private lb_wx:eui.Label;
    private lb_money:eui.Label;
    private lb_winList:eui.Label;

    private btn_sure:BaseButton;
    private btn_watch:BaseButton;
    private nameScroller:eui.Scroller;
    private nameList:eui.List;
    private endLessInfo;

    private group_list:eui.Group;
    private group_gift:eui.Group;

    constructor()
    {
        super('GiftView',{showBG:true});
    }

    public init()
    {
        super.init(true);
        let is_win_award = RoleCache.instance().isWeekLucky;//是否中奖了

        this.group_2.visible = is_win_award;
        this.group_1.visible = !is_win_award;
        if(is_win_award)
        this.requestInfo();
    }

    public requestInfo()
    {
        let data = {
            version:GameConst.version
        }
        HttpManager.instance().sendPost(GameConst.httpUrl + 'warrioruser/get_week_lucky', StringUtil.jsonToHttpPostString(data), (e)=>{
            let data = JSON.parse(e);
            if(data && data.data)
            {
                this.initUI(data.data);
            }
        })
    }

    public requsetList()
    {
        let sendParma = {
            version:GameConst.version
        }
        HttpManager.instance().sendPost(GameConst.httpUrl + 'warriorendless/get_week_lucky', StringUtil.jsonToHttpPostString(sendParma), (e)=>{
            let data = JSON.parse(e);
            if(data && data.data)
            {
                this.endLessInfo = data.data;
                this.showList();
            }
        }, this);
    }

    public showList()
    {
        if(this.endLessInfo)
        {
            let _listArr = new eui.ArrayCollection(this.endLessInfo);
            this.nameList.dataProvider = _listArr;
            this.nameList.itemRenderer = EndLessWinItem;
        }
    }

    public initUI(data)
    {
        if(data && data.self)
        {
            let money = data.money;
            let wx = data.wx;
            this.lb_wx.text = wx;
        }
    }

    public addEvent()
    {
        this.btn_sure.addTapHandler(this.close ,this);
        this.btn_watch.addTapHandler(this.watchList, this);
    }

    public watchList()
    {
        this.group_gift.visible = false;
        this.group_list.visible = true;
        this.img_tittle.source = 'title_list';
        this.requsetList();
    }
    
    public showWinList()
    {
        let data = {
            isPop:true,
            effect:1
        }
        UIManager.instance().openUILogic(EndLessWinListUI,data);
        this.remove(0);
    }

    protected close()
    {
        this.remove(1);
    }

    public removeEvent()
    {
        this.btn_sure.removeTapHandler();
        this.btn_watch.removeTapHandler();
    }

    public clear()
    {
        super.clear();
        this.endLessInfo = null;
        this.nameList.dataProvider = null;
        this.nameList.itemRenderer = null;
    }
}

enum GiftType
{
    default,
    win,
    Max
}